package com.sxds.wn.model;

import java.util.List;


/**
 * Description: <p>分页统计对象(分页处理中用到的页面对象)</p>
 * Content Desc:<p><p>
 * Copy Right of Sxdx-Wn
 * @author Andy
 * @version 1.0 Create Date:@2010-3-30
 */
public class Page extends BaseObject {

	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1230920302002L;
	//查询记录总页数
	private int totalPages = 0;
	//查询记录总数
	private int	totalObjects = 0;
	//查询记录要显示总页数的第n页,第一次查询时默认查询为第一页
	private int pageNumber = 1;
	//每页可以显示的记录数
	private int pageSize = 10;
	//是否使用分页功能,默认为分页
	private boolean enablePage = true;
	//从第n页的第一条记录开始查询
	private int queryFirstResult = 0;
	//查询记录结果列表
	private List results;
	private int beginPage;
	private int endPage;
	
	/**
	 * default construct with no params
	 */
	public Page(){}
	
	/**
	 * 根据参数计算属性值得
	 *
	 */
	public void calculate(){
		int pages = totalObjects/pageSize;
		totalPages = totalObjects % pageSize==0 ? pages : pages +1;
		queryFirstResult = pageSize * (this.pageNumber-1);
		//计算显示页码数量
		if( this.totalPages>0 && totalPages<=6){
			this.beginPage = 1;
			this.endPage = totalPages;
		}else{
			if( this.pageNumber-3<=0 ) this.beginPage = 1;
			if( this.pageNumber-3 >0 ) this.beginPage = this.pageNumber -3;
			if( this.pageNumber+3 <=totalPages ) this.endPage = this.pageNumber + 3;
			if( this.pageNumber+3 >=totalPages ) this.endPage = this.totalPages;
		}
	}
	
	/**
	 * 返回查询记录结果集
	 * @return java.utio.List
	 */
	public List getResults() {
		return results;
	}
	/**
	 * 设置结果集
	 * @param results java.util.List
	 */
	public void setResults(List results) {
		this.results = results;
	}

	public int getPageNumber() {
		return pageNumber;
	}
	public void setPageNumber(int pageNumber) {
		if( pageNumber<=0 ){
			throw new IllegalArgumentException("pageNumber must >0");
		}
		this.pageNumber = pageNumber;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalObjects() {
		return totalObjects;
	}
	public void setTotalObjects(int totalObjects) {
		this.totalObjects = totalObjects;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public boolean isEnablePage() {
		return enablePage;
	}

	public void setEnablePage(boolean enablePage) {
		this.enablePage = enablePage;
	}

	public int getQueryFirstResult() {
		return queryFirstResult;
	}

	public void setQueryFirstResult(int queryFirstResult) {
		this.queryFirstResult = queryFirstResult;
	}
	
	public int getMaxResults(){
		return this.queryFirstResult + this.pageSize;
	}

	/**
	 * @return the beginPage
	 */
	public int getBeginPage() {
		return beginPage;
	}

	/**
	 * @param beginPage the beginPage to set
	 */
	public void setBeginPage(int beginPage) {
		this.beginPage = beginPage;
	}

	/**
	 * @return the endPage
	 */
	public int getEndPage() {
		return endPage;
	}

	/**
	 * @param endPage the endPage to set
	 */
	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}
}
